package com.sl.au.controller;

import java.util.ArrayList;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.sl.au.entity.BusinesssellerAuthentication;
import com.sl.au.entity.EventRegister;
import com.sl.au.entity.ViewForEventRegisterTask;
import com.sl.au.entity.EventReport;
import com.sl.au.entity.Grading;
import com.sl.au.entity.GridAreaInfo;
import com.sl.au.entity.EventTask;
import com.sl.au.entity.Option;
import com.sl.au.entity.UserSingle;
import com.sl.au.entity.User;
import com.sl.au.entity.EventToEvaluateUser;
import com.sl.au.service.EventReportService;
import com.sl.au.service.EventRegisterService;
import com.sl.au.service.UserService;
import com.sl.au.service.OptionService;
import com.sl.au.service.GradingService;
import com.sl.au.service.GridAreaInfoService;
import com.sl.au.service.IdentifyService;

import com.sl.utils.MsgHelper;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping(value = "/ui/eventRegisterDeal")
public class EventRegisterDealController extends BaseController {
	
	@Autowired
	EventRegisterService eventRegisterService;
	@Autowired
	OptionService optionService;
	
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView index(ModelAndView modelAndView) {
		modelAndView = createLayoutView("eventRegister/eventRegisterDeal");
		return modelAndView;
	}
	
	
	@RequestMapping(value = "getpage", method = RequestMethod.GET)
	public Map<String, Object> getpage(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		int start = Integer.parseInt(request.getParameter("start"));
		int length = Integer.parseInt(request.getParameter("length"));
		String key=request.getParameter("key");
		String userId = this.getMyAccount().getUser().getId();
		Option starte = optionService.getRepository().findByTitleAndGroup("已完结", "内部事件流转状态");
		String starteId = "";
		if(starte != null) {
			starteId = starte.getId();
		}
//		List<ViewForEventRegisterTask> eventRegister = null;
//		int count=0;
//		eventRegister = eventRegisterService.getPageByTaskStateAndOperate(start, length, starteId, userId, key, "eventTaskTime", Sort.Direction.ASC);
//		count = eventRegisterService.getCountByTaskStateAndOperateUser(starteId, userId, key);

		List<Map<String, Object>> eventRegister = null;
		int count=0;
		String roleId = this.getMyAccount().getRole().getId();
		eventRegister = eventRegisterService.getPageByTaskStateAndOperateAndRole(start, length, roleId, starteId, userId, key, "eventTaskTime", "ASC");
		count = eventRegisterService.getCountByTaskStateAndOperateUserAndRole(roleId, starteId, userId, key);
		map.put("data", eventRegister);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}
	
}
